<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/14 0014
 * Time: 下午 3:35
 */

namespace App\Enum;


use App\GameService\games\PlayHelp;
use App\Utility\BaseEnum;

/**
 * 麻将数据
 * @author XCH
 *
 */
class MahjEnum
{
    protected static $instance = null;
    protected static $win_water_dott = 0.05;  //抽水只针对最后的赢钱的玩家；
    //牌花色：大小王
    
    //麻奖的花筒1筒－9筒 ；A 白板
    const MJ_CARD_TONG = [ 0X01,0X02,0X03,0X04,0X05,0X06,0X07,0X08,0X09,0X0A];  
    // 二八杠 麻将点；
    const MAJIANG_NAMES = ['1'=>'一筒','2'=>'两筒','3'=>'三筒','4'=>'四筒','5'=>'五筒','6'=>'六筒','7'=>'七筒','8'=>'八筒','9'=>'九筒','A'=>'白板'];
    const MAJIANG_NUMS =  ['1'=>1,'2'=>2,'3'=>3,'4' => 4,'5' => 5,'6'=>6,'7'=>7,'8'=>8,'9'=>9,'A'=>0];
    
    
    /**
     * 二八杠的等级大小；
     * @var 16进制值
     */
    const GAME_0X3E = 14;   // 等级状态值 ：47 五小牛
    const GAME_0X3D = 13;   // 等级状态值 ：46 四炸
    const GAME_0X3C = 12;   // 等级状态值 ：45 五花牛
    const GAME_0X3B = 11;   // 等级状态值 ：44 四花牛
    const GAME_0X3A = 10;   // 等级状态值 ：43 牛牛
    const GAME_0X39 = 9;    // 等级状态值 ：42 牛九
    const GAME_0X38 = 8;	// 牛八
    const GAME_0X37 = 7;	// 牛七
    const GAME_0X36 = 6;	// 牛六
    const GAME_0X35 = 5;	// 牛五
    const GAME_0X34 = 4;	// 牛四
    const GAME_0X33 = 3;	// 牛三
    const GAME_0X32 = 2;	// 一点半
    const GAME_0X31 = 1;	// 一点
    const GAME_0X30 = 0;	// 鳖十
    
    //TODO 游戏类型的名称 五小牛，四炸，五花牛，四花牛，牛牛，牛九.... > 牛一，没牛
    const GAME_NIUNIU_LEVEL = [
        20=>'天王',
        19=>'九宝',
        18=>'八宝',
        17=>'七宝',
        16=>'六宝',
        15=>'五宝',
        14=>'四宝',
        13=>'三宝',
        12=>'二宝',
        11=>'一宝',
        10=>'二八杠',        
        9=>'九点',
        8=>'八点',
        7=>'七点',
        6=>'六点',
        5=>'五点',
        4=>'四点',
        3=>'三点',
        2=>'二点',
        1=>'一点',
        0=>'鳖十',
    ];
    
    
    //TODO 骨牌数据  牌九单牌第一位为等级，第二位为点数
    const P9_NUM_1 = 0X03;  //丁三(红三点) -3
    const P9_NUM_2 = 0X06;  //二四(红六点) -6
    const P9_NUM_3 = 0X05;  //杂五    -5
    const P9_NUM_4 = 0X15;  //杂五    -21
    const P9_NUM_5 = 0X07;  //杂七    -7
    const P9_NUM_6 = 0X17;  //杂七    -23
    const P9_NUM_7 = 0X08;  //杂八    -8
    const P9_NUM_8 = 0X18;  //杂八    -24
    const P9_NUM_9 = 0X09;  //杂九    -9
    const P9_NUM_10 = 0X19;  //杂九   -25
    const P9_NUM_11 = 0X26;  //么五(零霖六)  -38
    const P9_NUM_12 = 0X27;  //么六(高脚七)  -39
    const P9_NUM_13 = 0X30;  //四六(红头十)  -48
    const P9_NUM_14 = 0X31;  //斧头   -49
    const P9_NUM_15 = 0X34;  //板凳   -52
    const P9_NUM_16 = 0X36;  //长牌 （长三）  -54
    const P9_NUM_17 = 0X40;  //梅牌   -80
    const P9_NUM_18 = 0X44;  //和牌   -68
    const P9_NUM_19 = 0X48;  //人牌   -72
    const P9_NUM_20 = 0X52;  //地牌   -82
    const P9_NUM_21 = 0X62;  //天牌   -98
    
    /**
     * 构造函数
     * @param array $options 参数
     * @access public
     */
    public function __construct($options = [])
    {
    }
    
    //单牌大小大小；
    protected static function getGrabDan(){
        $myLists = array(
            self::P9_NUM_1  => 1,
            self::P9_NUM_2  => 2,
            self::P9_NUM_3  => 3,
            self::P9_NUM_4  => 3,
            self::P9_NUM_5  => 5,
            self::P9_NUM_6  => 5,
            self::P9_NUM_7  => 8,
            self::P9_NUM_8  => 8,
            self::P9_NUM_9  => 9,
            self::P9_NUM_10 => 9,
            self::P9_NUM_11 => 11,
            self::P9_NUM_12 => 12,
            self::P9_NUM_13 => 13,
            self::P9_NUM_14 => 14,
            self::P9_NUM_15 => 15,
            self::P9_NUM_16 => 16,
            self::P9_NUM_17 => 17,
            self::P9_NUM_18 => 18,
            self::P9_NUM_19 => 19,
            self::P9_NUM_20 => 20,
            self::P9_NUM_21 => 21
        );
        return $myLists;
    }
    
    
    /**
     * 排序，默认正序
     */
    protected static function sortGrabNums(& $cards , $desc = FALSE){
        $newArr = [];
        $alls = self::getGrabDan();
        foreach ($cards as $rv) {
            $newval = $alls[$rv] ?? 0;
            $newArr[$newval] = $rv;
        }
        if ($desc === TRUE) 
            krsort($newArr);  //倒序
        else 
            ksort($newArr);
        $cards = !empty($newArr) ? array_values($newArr) : FALSE;
    }
    
    /**
     * 获取骨牌整副牌数据
     */
    protected static function getGrabP9Cards(){
        $allCards = [
            self::P9_NUM_1,       //丁三(红三点)
            self::P9_NUM_2,       //二四(红六点)
            self::P9_NUM_3,self::P9_NUM_4,  //杂五
            self::P9_NUM_5,self::P9_NUM_6,  //杂七
            self::P9_NUM_7,self::P9_NUM_8,  //杂八
            self::P9_NUM_9,self::P9_NUM_10,  //杂九
            self::P9_NUM_21,self::P9_NUM_21,  //天牌
            self::P9_NUM_20,self::P9_NUM_20,  //地牌
            self::P9_NUM_19,self::P9_NUM_19,  //人牌
            self::P9_NUM_18,self::P9_NUM_18,  //和牌（ 鹅）
            self::P9_NUM_17,self::P9_NUM_17,  //梅牌
            self::P9_NUM_16,self::P9_NUM_16,  //长牌 （长三）
            self::P9_NUM_15,self::P9_NUM_15,  //板凳
            self::P9_NUM_14,self::P9_NUM_14,  //斧头
            self::P9_NUM_13,self::P9_NUM_13,  //四六(红头十)
            self::P9_NUM_12,self::P9_NUM_12,  //么六(高脚七)
            self::P9_NUM_11,self::P9_NUM_11,  //么五(零霖六)
        ];
        return $allCards;
    }
    
    /**
     * 获取骨牌对牌配置
     * 创建对牌；
     * 注意：
     * 对牌 P9_NUM_10 = 0X19  为杂牌中不带红色的牌（即纯黑色或纯白色那张）
     * 对牌 P9_NUM_8 = 0X18   为杂牌中不带红色的牌（即纯黑色或纯白色那张）
     * 对牌 P9_NUM_6 = 0X17   为杂牌中不带红色的牌（即纯黑色或纯白色那张）
     */
    public static function getGrabDuiConfig(){
        $allDuis = [
            ["key"=>31,'name'=>'至尊','nums'=> [self::P9_NUM_1,self::P9_NUM_2]],
            ["key"=>30,'name'=>'双天','nums'=> [self::P9_NUM_21,self::P9_NUM_21] ],
            ["key"=>28,'name'=>'双地','nums'=> [self::P9_NUM_20,self::P9_NUM_20] ],
            ["key"=>28,'name'=>'双人','nums'=> [self::P9_NUM_19,self::P9_NUM_19] ],
            ["key"=>27,'name'=>'双鹅','nums'=> [self::P9_NUM_18,self::P9_NUM_18] ],
            ["key"=>26,'name'=>'双梅','nums'=> [self::P9_NUM_17,self::P9_NUM_17] ],
            ["key"=>25,'name'=>'双长三','nums'=> [self::P9_NUM_16,self::P9_NUM_16] ],
            ["key"=>24,'name'=>'双板凳','nums'=> [self::P9_NUM_15,self::P9_NUM_15] ],
            ["key"=>23,'name'=>'双斧头','nums'=> [self::P9_NUM_14,self::P9_NUM_14] ],
            ["key"=>22,'name'=>'双红头','nums'=> [self::P9_NUM_13,self::P9_NUM_13] ],
            ["key"=>21,'name'=>'双高脚','nums'=> [self::P9_NUM_12,self::P9_NUM_12] ],
            ["key"=>20,'name'=>'双零霖','nums'=> [self::P9_NUM_11,self::P9_NUM_11] ],
            ["key"=>19,'name'=>'杂九','nums'=> [self::P9_NUM_9,self::P9_NUM_10] ],
            ["key"=>18,'name'=>'杂八','nums'=> [self::P9_NUM_7,self::P9_NUM_8] ],
            ["key"=>17,'name'=>'杂七','nums'=> [self::P9_NUM_5,self::P9_NUM_6] ],
            ["key"=>16,'name'=>'杂五','nums'=> [self::P9_NUM_3,self::P9_NUM_4] ],
            ["key"=>15,'name'=>'天王','nums'=> [self::P9_NUM_10,self::P9_NUM_21] ],
            ["key"=>14,'name'=>'地王','nums'=> [self::P9_NUM_10,self::P9_NUM_20] ],
            ["key"=>13,'name'=>'天杠','nums'=> [self::P9_NUM_8,self::P9_NUM_21] ],
            ["key"=>12,'name'=>'地杠','nums'=> [self::P9_NUM_8,self::P9_NUM_20] ],
            ["key"=>11,'name'=>'天高九','nums'=> [self::P9_NUM_6,self::P9_NUM_21] ],
            ["key"=>10,'name'=>'地高九','nums'=> [self::P9_NUM_6,self::P9_NUM_20] ],
            ["key"=>9,'name'=>'九点','nums'=> FALSE ],
            ["key"=>8,'name'=>'八点','nums'=> FALSE ],
            ["key"=>7,'name'=>'七点','nums'=> FALSE ],
            ["key"=>6,'name'=>'六点','nums'=> FALSE ],
            ["key"=>5,'name'=>'五点','nums'=> FALSE ],
            ["key"=>4,'name'=>'四点','nums'=> FALSE ],
            ["key"=>3,'name'=>'三点','nums'=> FALSE ],
            ["key"=>2,'name'=>'二点','nums'=> FALSE ],
            ["key"=>1,'name'=>'一点','nums'=> FALSE ],
            ["key"=>0,'name'=>'零点','nums'=> FALSE ],
        ];
        return $allDuis;
    }
    
    
    //计算点数；
    public static function getCardDott($cval=false) {
        if($cval===false)return FALSE;
        $res = $cval & 0x0f ;
        return $res;
    }
    //计算花色；
    public static function getCardHua($cval=false) {
        if($cval===false)return FALSE;
        $res =  ($cval & 0xf0) / 16 ;
        return $res;
    }
    
  
    /**
     * 比较两手牌的大小
     * @param array $cards1
     * @param array $cards2
     */
    public static function gatherCardSize($cards1,$cards2,$number = 2) {
        $defWinFlag = 0; 
        if (!$cards1 || !$cards2 || sizeof($cards1) != $number  ||sizeof($cards2) != $number) {
            return FALSE;
        }
        self::sortGrabNums($cards1,TRUE);    //对比大小；要把数组排下序(倒序)
        self::sortGrabNums($cards2,TRUE);
        //对比两张排的大小
        $tempFlag = FALSE;
        $start_off = 0; 
        $allBots = self::getGrabDan();
        
        do{
            if ($start_off >= $number) { break;}
            //比牌大小
            $num1 = $cards1[$start_off] ?? 0;
            $num2 = $cards2[$start_off] ?? 0;
            $size1 = isset($allBots[$num1]) ? intval($allBots[$num1]) :0 ;
            $size2 = isset($allBots[$num2]) ? intval($allBots[$num2]) :0 ;
            
            //第二位大于第一位为 闲家赢
            if($size1 > 0  && $size2>0 && $size2 > $size1){
                $tempFlag = TRUE;   //比牌结束
                $defWinFlag = 2;    // 闲家赢
                break;
            }else if ($size1 > 0  && $size2>0 && $size2 < $size1){ //第一位大牌相同对比第二位
                $tempFlag = TRUE;   //比牌结束
                $defWinFlag = 1;    //庄家赢
                break;
            }else{
                $tempFlag = FALSE;   //比牌结束
                $start_off ++;
            }
        }while ($tempFlag !== TRUE);
        if($start_off >= $number && $defWinFlag === 0){
            $defWinFlag = 100;      //对比和局
        }
        return $defWinFlag;
    }
    
    
    /**
     * 生成二八杠的牌数据
     * @param int $playerNum
     * @param boolean $param
     * @param boolean $sigle
     */
    public static function createRoomGameTWOEBAR($playerNum,$param = FALSE,$currentJu = 0){
        $allCards = self::MJ_CARD_TONG;     //所有手牌信息； 都要保存(40张牌 1－9 白板)；
        $allCardsList = [] ; 
        $everyCard = 2;  //每人5张牌
        $playerNum = 4 ; //每次都要发4个人的手牌信息
        $gameCommNo = isset($param['gameJu']) ? $param['gameJu'] : 0;                                   //牌公共局号
        $currentJu = isset($param['currInning']) ? intval($param['currInning']) : 1;                    //当前局号(后10位相同)
        foreach ($allCards as $cor){
            $allCardsList = array_merge($allCardsList , [$cor,$cor,$cor,$cor]);       //40张牌；
        }
        @shuffle($allCardsList);    //洗牌；
        //记录索引值；
        $userCards = [];
        //取出历史记录的牌的数量；每张牌的数量不能超过4张； 
        $alreadyCards = [];
        $commJuData = PlayHelp::getInstance()-> getRoomCards($gameCommNo);                              //公共局号里的棋牌数据；
        if(!$commJuData){ //第一次进来
            $commJuData = ["ju" => 0,"all_nums" => implode(",", $allCardsList) ,"cards_nums"=>[],"cards"=>[] ];                //默认局
        }
        if(isset($commJuData["cards_nums"]) && !empty($commJuData["cards_nums"])){  //已发过牌的数据统计；
            $alreadyCards = $commJuData["cards_nums"];
            $allCardsList = !empty($commJuData["all_nums"]) ? explode(',', $commJuData["all_nums"]) : $allCardsList;
        }
        
        //每个用户发几张牌；
        $everytotal = $everyCard * $playerNum;
        //取牌数据为每次取八张牌；
        $start_offen = ($currentJu >= 1) ? ($currentJu - 1) * $everytotal :0 ;
        $tempArray = array_slice($allCardsList, $start_offen,$everytotal);  //取出总牌；
        if (!empty($tempArray) && sizeof($tempArray) > 2) {
            foreach ($tempArray as $r => $fo){
                $paikey =  "num_" . $fo ;          //牌值数据
                if (!isset($alreadyCards[$paikey])) { $alreadyCards[$paikey] = 0 ;}
                $alreadyCards[$paikey] ++ ;  //修改为引用次数；
            }
            for ($i = 0; $i < $playerNum; $i++) {
                $off = ($i * $everyCard);
                $templist = array_slice($tempArray, $off , $everyCard);
                if (!empty($templist)) {
                    foreach ($templist as &$rv){ $rv = intval($rv); }
                }
                $userCards[$i] = $templist;
            }
        }
        $commJuData['ju'] = $currentJu;
        $commJuData['cards_nums'] = $alreadyCards;                                  //当前局的牌数据内容；
        $commJuData['cards'][$currentJu] = json_encode($userCards);                 //每一局的棋牌数据格式都保存在cards中；
        PlayHelp::getInstance()-> setRoomCards($gameCommNo,$commJuData);            //用户的数据存储起来；    发牌先不解析；
        BaseEnum::wirteRedisData(SysEnum::BASEDB_GAMECARD_KEY,BaseEnum::JsonEncode($commJuData),$gameCommNo);  //内存数据缓存写入Redis；
        return  $userCards ; //手牌数据； 
    }
    
    
    /**
     * 创建牌九的牌型数据
     * @param int $playerNum
     * @param boolean $param
     * @param number $currentJu
     * @return array[]
     */
    public static function createRoomGameQZGRAB($playerNum,$param = FALSE,$currentJu = 0){
        $allCardsList = self::getGrabP9Cards();     //所有手牌信息； 都要保存(32张骨牌)；
        $everyCard = 2;  //每人5张牌
        $playerNum = 4 ; //每次都要发4个人的手牌信息
        $gameCommNo = isset($param['gameJu']) ? $param['gameJu'] : 0;                        //牌公共局号
        $currentJu = isset($param['currInning']) ? intval($param['currInning']) : $currentJu;        //当前局号
        
        @shuffle($allCardsList);    //洗牌；
        
        //记录索引值；
        $userCards = [];
        //取出历史记录的牌的数量；每张牌的数量不能超过4张；
        $alreadyCards = [];
        $commJuData = PlayHelp::getInstance()-> getRoomCards($gameCommNo);          //公共局号里的棋牌数据；
        
        
        if(!$commJuData){ //第一次进来
            $commJuData = ["ju" => 0,"all_nums" => implode(",", $allCardsList) ,"cards_nums"=>[],"cards"=>[] ];                //默认局
        }
        if(isset($commJuData["cards_nums"]) && !empty($commJuData["cards_nums"])){  //已发过牌的数据统计；
            $alreadyCards = $commJuData["cards_nums"];
            $allCardsList = !empty($commJuData["all_nums"]) ? explode(',', $commJuData["all_nums"]) : $allCardsList;
        }
        
        //每个用户发几张牌；
        $everytotal = $everyCard * $playerNum;
        //取牌数据为每次取八张牌；
        $start_offen = $currentJu * $everytotal;
        $tempArray = array_slice($allCardsList, $start_offen,$everytotal);  //取出总牌；
        if (!empty($tempArray) && sizeof($tempArray) > 2) {
            foreach ($tempArray as $r => $fo){
                $paikey =  "num_" . $fo ;               //牌值数据
                if (!isset($alreadyCards[$paikey])) { $alreadyCards[$paikey] = 0 ;}
                $alreadyCards[$paikey] ++ ;             //修改为引用次数；
            }
            for ($i = 0; $i < $playerNum; $i++) {
                $off = ($i * $everyCard);
                $templist = array_slice($tempArray, $off , $everyCard);
                if (!empty($templist)) {
                    foreach ($templist as &$rv){ $rv = intval($rv); }
                }
                $userCards[$i] = $templist;
            }
        }
        $currentJu = $currentJu + 1 ;
        $commJuData['ju'] = $currentJu;
        $commJuData['cards_nums'] = $alreadyCards;                                  //当前局的牌数据内容；
        $commJuData['cards'][$currentJu] = BaseEnum::JsonEncode($userCards);        //每一局的棋牌数据格式都保存在cards中；
        PlayHelp::getInstance()-> setRoomCards($gameCommNo,$commJuData);            //用户的数据存储起来；    发牌先不解析；
        BaseEnum::wirteRedisData(SysEnum::BASEDB_GAMECARD_KEY,BaseEnum::JsonEncode($commJuData),$gameCommNo);  //内存数据缓存写入Redis；
        return  $userCards ; //手牌数据；
    }
    
    //获取两张牌的点数
    protected static function getDottod($paiNums,&$maxCardChar = 0) {
        $allNumVals = self::MJ_CARD_TONG;
        if(!$paiNums) return  false;
        $totalDott = 0;                 //总点数
        $maxCardChar = max($paiNums);   //取最大牌；
        foreach ($paiNums as $oneNum){
            $dottVal = intval($oneNum);
            if(in_array($oneNum, $allNumVals,true) && $oneNum == 0X0A ){
                $dottVal = 0.5;
                $maxCardChar = 0;
            }
            $totalDott += $dottVal ;  //点数；
        }
        if ($totalDott >= 10) {
            $totalDott =  $totalDott % 10 ;
        }
        return $totalDott;
    }
    
    
    /**
     * 计算二八的大小值
     * @param boolean $nums 牌值KEY
     * @param number $niuLevel 牌值的等级，
     * @param number $niu_mutle 牌值的倍数，
     * @return boolean|number[]|string[]|mixed[]
     */
    public static function dealTwoEightLevel($nums = false , & $niuLevel = 0,& $niu_mutle = 1) {
        if(!$nums) return false ;
        $baseLevels = self::GAME_NIUNIU_LEVEL;
        //牌型：天王 > 九宝 > 八宝 > 一宝  >二八杠 > 九点半 > ..... 八 ，七 ..一点， 
        $maxCardChar = 0;                   //为点数时：取最大牌的点
        $all_ddt = array_sum($nums);        //总和；
        $all_ddt_val = $all_ddt % 10;       //总和取余数为0；
        $uniqDotts= array_unique($nums);
        
        $oneKeyVal = reset($uniqDotts);
        
        //天王到  多宝；
        if(!empty($uniqDotts) && sizeof($uniqDotts) === 1){ 
            if ($oneKeyVal === 10) { //天王
                $niuLevel = 20; 
            }else{
                $niuLevel = 10 + intval($oneKeyVal); //  17 == 七宝值
            }
        }
        //二八杠 和 鳖十
        else if($all_ddt === 10 && $all_ddt_val === 0) {
            @sort($uniqDotts);
            $tempStr = implode("|", $uniqDotts);
            
            //10点：有四种情况 2-8, 1-9, 3-7, 4-6
            if (isset($tempStr) && $tempStr == "2|8" ) {
                $niuLevel = 10 ;
            }else{
                $niuLevel = 0 ;
                $maxCardChar = max($uniqDotts);             //取最大牌；
                
            }
        }else {  
            //取点数和；
            $niuLevel = self::getDottod($nums,$maxCardChar); //计算牛牛的规则；
        }
        
        //取牌型名称；
        $tempIndx = intval($niuLevel);
        $tempLen = "{$niuLevel}";
        $niuName = isset($baseLevels[$tempIndx]) ?$baseLevels[$tempIndx] : "";
        if($niuLevel > 0 && intval($niuLevel) > 0 && substr($tempLen, -2) == '.5'){  //半点值
            $niuName .= '半'; 
        }
        $niuLevs = array("key"=> $niuLevel ,'name'=> $niuName,"maxCardKey" => $maxCardChar,"mutl_value"=> 1,"cards"=>implode(',', $nums));
        return $niuLevs;
    }
    
    
    
    /**
     * 计算牌九的等级值
     * @param boolean $nums 牌值KEY
     * @param number $niuLevel 牌值的等级，
     * @param number $niu_mutle 牌值的倍数，
     * @return boolean|number[]|string[]|mixed[]
     */
    public static function dealGrabNineLevel($nums = false , & $findIsLevel = 0,& $niu_mutle = 1) {
        $allLevList = self::getGrabDuiConfig(); //所有牌型组成号码
        if(!$nums || empty($allLevList)) return false ;
        $baseLevels = !empty($allLevList) ? array_column($allLevList, "name",'key') : FALSE ;   //所有牌型 
        
        //TODO 查询号码是哪种牌型值；
        $findIsLevelName = '';
        foreach ($allLevList as $sysNums) {
            if(isset($sysNums['key']) && intval($sysNums['key']) >= 10 && isset($sysNums['nums']) && !empty($sysNums['nums'])){
                $diffRes = (!empty($sysNums['nums'])) ? array_diff($nums,$sysNums['nums']) : FALSE; //排序MD5值性能不高 | 使用 Array 对比一下；
                if(!empty($sysNums) && $diffRes !== FALSE && empty($diffRes)){
                    $findIsLevel = intval($sysNums['key']);  //对比值；如果值为Empty则成功
                    $findIsLevelName = isset($sysNums['name']) ? $sysNums['name'] : '';
                    break;
                }
            }
        }
        
        //TODO 上面的牌型都不是那就计算点数
        if ($findIsLevel <= 0) {
            $totalSum = 0;      
            foreach ($nums as $oneVal){
                $totalSum += self::getCardDott($oneVal);            //计算总点值和
            }
            $findIsLevel = ($totalSum >0) ? $totalSum % 10  : 0;    //计算点数；
            $findIsLevelName = isset($baseLevels[$findIsLevel]) ? $baseLevels[$findIsLevel] : '';
        }
        
        //计算总值
        $niuLevs = array("key"=> $findIsLevel ,'name'=> $findIsLevelName,"maxCardKey" => FALSE,"mutl_value"=> 1 ,"cards"=>implode(',', $nums));
        return $niuLevs;
    }
    
    
    /**
     * 计算下注最高倍数
     */
    public static function countDeskMaxMutle($totalNum,$zjMuts,$zjPoints,$fjInfo=false){
        $roomEveryPots = isset($fjInfo["everyPoints"]) ? floatval($fjInfo["everyPoints"]) :0 ;  //房间底分
        $minMutl = isset($fjInfo["minMultiple"]) ? intval($fjInfo["minMultiple"]) :0 ;          //房间最高倍
        $maxMutl = isset($fjInfo["maxMultiple"]) ? intval($fjInfo["maxMultiple"]) :0 ;          //房间最高倍
        //BaseEnum::Logger("计算倍数参数：everyPoints={$roomEveryPots},minMutl={$minMutl},maxMutl={$maxMutl},totalNum={$totalNum},zjPoints={$zjPoints},zjMutls ={$zjMuts}===",self::class);
        if(!$totalNum || intval($totalNum) < 2 || intval($zjMuts) <= 0  ||!$zjPoints || !$fjInfo || !$roomEveryPots) return 0;
        $lastNum = $totalNum - 1;
        $lastTimes = intval($zjPoints / ($roomEveryPots * 4 * $zjMuts * $lastNum)) ;            //取理论值；
        if (isset($maxMutl) && $maxMutl > 0 && $lastTimes > $maxMutl) {
            $lastTimes = $maxMutl; //不超过最高倍；
        }
        //BaseEnum::Logger("计算倍数结果：lastTimes={$lastTimes},lastNum={$lastNum} ===",self::class);
        return $lastTimes > 0 ? $lastTimes : 0;
    }
    
     
    
    
    
    
    

     
}